package com.ftwj.demo.modular.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ftwj.demo.config.swagger.HttpMethod;
import com.ftwj.demo.modular.service.ExcelService;
import com.ftwj.demo.utils.result.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
* <p>Title: ExcelController</p>  
* <p>Description: excel导入导出</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* <p>Company: 兰州飞天网景信息产业有限公司</p>    
* @author HeYang
* @date 2020年4月21日 下午6:15:54
* @version V1.0
 */
@RestController 
@Api(tags="导入导出接口", value="Excel操作")
@Validated
public class ExcelController {
	
	@Autowired
	private ExcelService service;
	
	/**
	 * <p>Title: exportExcel</p>  
	 * <p>Description: 直接导出</p>  
	 * @param response 
	 * @author HeYang
	 * @date 2020年4月21日  
	 * @version 1.0
	 */
	@RequestMapping(value = "/excel/export", method = RequestMethod.GET)
	@ApiOperation(value="excel无模板直接导出", notes="数据",code=0,httpMethod=HttpMethod.GET)
	public void exportExcel(HttpServletResponse response) {
		service.exportExcel(response);
	}
	
	/**
	 * <p>Title: importExcel</p>  
	 * <p>Description: 直接导入</p>  
	 * @param file
	 * @author HeYang
	 * @date 2020年4月21日  
	 * @version 1.0
	 */
	@RequestMapping(value = "/excel/import", method = RequestMethod.POST)
	@ApiOperation(value="excel无模板直接导入", notes="数据",code=0,httpMethod=HttpMethod.POST)
	public ResultBean<?> importExcel(@RequestParam("file") MultipartFile file) {
		service.importExcel(file);
	    return ResultBean.success();
	}
	
	/**
     * <p>Title: exportExcelTemp</p>  
     * <p>Description: excel模板导入</p>  
     * @param response
     * @param templatePath 获取导出excel指定模版
     * @param excelName   文件名称
     * @author HeYang
     * @date 2020年4月26日  
     * @version 1.0
     */
    @GetMapping(value="/excel/template/export")
	@ApiOperation(value="excel模板导出", notes="数据",code=0,httpMethod=HttpMethod.GET)
    public void exportExcelTemp(HttpServletResponse response,HttpServletRequest request
    		,@RequestParam String excelName){
    	service.exportExcel(response,request,excelName);
    }
	
	/**
	 * <p>Title: excelToHtml</p>  
	 * <p>Description: xls和xlsx都这样转html</p>  
	 * @param response
	 * @param path 
	 * @author HeYang
	 * @date 2020年4月26日  
	 * @version 1.0
	 */
    @RequestMapping("/excel/preview")
    @ApiOperation(value="excel转html", notes="数据",code=0,httpMethod=HttpMethod.GET)
    public void excelToHtml(HttpServletResponse response,@RequestParam(name = "path") String path) {
//    	String path = "D:/exporttemp_03.xls";//D:/exporttemp_07.xlsx
    	service.excelToHtml(response,path);
    }
    
    /**
     * <p>Title: wordExport</p>  
     * <p>Description: word导出</p>  
     * @param response
     * @param request 
     * @author HeYang
     * @date 2020年4月21日  
     * @version 1.0
     */
    @RequestMapping("/word/template/export")
    @ApiOperation(value="导出word", notes="数据",code=0,httpMethod=HttpMethod.GET)
    public void wordExport(HttpServletRequest request,HttpServletResponse response) {
    	service.wordExport(request,response);
    }
    
    /**
     * <p>Title: cvsExport</p>  
     * <p>Description: 导出cvs</p>  
     * @param request
     * @param response 
     * @author HeYang
     * @date 2020年4月22日  
     * @version 1.0
     */
    @GetMapping("/cvs/export")
    @ApiOperation(value="导出cvs", notes="数据",code=0,httpMethod=HttpMethod.GET)
    public void cvsExport(HttpServletRequest request,HttpServletResponse response) {
    	service.cvsExport(request,response);
    }
    
    /**
     * <p>Title: complexExport</p>  
     * <p>Description: 联表查询</p>  
     * @param request
     * @param response 
     * @author HeYang
     * @date 2020年4月22日  
     * @version 1.0
     */
    @GetMapping("/excel/complex/export")
    @ApiOperation(value="联表查询复杂导出", notes="数据",code=0,httpMethod=HttpMethod.GET)
    public void complexExport(HttpServletRequest request,HttpServletResponse response) {
    	service.complexExport(request,response);
    }
    
    /**
     * <p>Title: importBigExcel</p>  
     * <p>Description: excel大数据导入</p>  
     * @param file
     * @return 
     * @author HeYang
     * @date 2020年4月23日  
     * @version 1.0
     */
    @RequestMapping(value = "/cvs/import", method = RequestMethod.POST)
	@ApiOperation(value="excel大数据cvs导入", notes="数据",code=0,httpMethod=HttpMethod.POST)
	public ResultBean<?> importBigExcel(@RequestParam("file") MultipartFile file) {
		service.bigDateImport(file);
	    return ResultBean.success();
	}
    
    /**
     * <p>Title: userExport</p>  
     * <p>Description: 用户简单导出</p>  
     * @param request
     * @param response 
     * @author HeYang
     * @date 2020年4月26日  
     * @version 1.0
     */
    @GetMapping("/excel/user/export")
    @ApiOperation(value="用户数据联表查询复杂导出", notes="数据",code=0,httpMethod=HttpMethod.GET)
    public void userExport(HttpServletRequest request,HttpServletResponse response,@RequestParam(required = false) String excelName
    		,@RequestParam(required = false) String name,@RequestParam(required = false) String phone
    		,@RequestParam(required = false) String card,@RequestParam(required = false) String gender,@RequestParam(required = false) String address
    		,@RequestParam(required = false) String area,@RequestParam(required = false) String dept) {
    	service.userComplexExport(request,response,excelName,name,phone,card,gender,address,area,dept);
    }
    
}
